Skip to content

uniform color handling between labels and points/shapes#497

Merged
timtreis merged 11 commits intomainfrom
feature/refactor_label_color_handling
Mar 11, 2026
Merged

uniform color handling between labels and points/shapes#497
timtreis merged 11 commits intomainfrom
feature/refactor_label_color_handling

Conversation

@Sonja-Stockhaus
Copy link
Collaborator

As mentioned in #478, here we adapt the color handling of labels so that it works the same way as points/shapes (e.g. you can pass any color like...)

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.01%. Comparing base (a2bb56b) to head (6054d6c).

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/utils.py 95.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #497   +/-   ##
=======================================
  Coverage   84.00%   84.01%           
=======================================
  Files           9        9           
  Lines        2601     2608    +7     
=======================================
+ Hits         2185     2191    +6     
- Misses        416      417    +1     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/basic.py 91.63% <100.00%> (-0.03%) ⬇️
src/spatialdata_plot/pl/render.py 88.95% <100.00%> (+0.02%) ⬆️
src/spatialdata_plot/pl/render_params.py 90.30% <100.00%> (+0.04%) ⬆️
src/spatialdata_plot/pl/utils.py 79.32% <95.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timtreis timtreis marked this pull request as ready for review October 20, 2025 16:47
@timtreis timtreis force-pushed the feature/refactor_label_color_handling branch 3 times, most recently from 6338980 to c31d2e9 Compare March 5, 2026 21:40
timtreis and others added 4 commits March 11, 2026 14:29
…lor='red'`

Labels now use the same color/col_for_color split as shapes and points,
so `render_labels(color="red")` is correctly recognized as a literal
color instead of being treated as a column name. Fixes #470 and #478.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use `is not None` instead of truthiness check, matching shapes/points
- Pass overridden na_color to _map_color_seg so labels not in the table
  respect the literal color when one is set

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When color is a literal value (not a column name), the groups parameter
has no effect. Added a warning for labels, points, and shapes so users
aren't silently confused.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Extract duplicated groups-ignored warning string to _GROUPS_IGNORED_WARNING
- Add col_for_color guard to na_color override, matching the points pattern

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timtreis timtreis force-pushed the feature/refactor_label_color_handling branch from b17fad5 to 35014ff Compare March 11, 2026 13:30
timtreis and others added 7 commits March 11, 2026 14:33
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Change `color: str | None` to `color: ColorLike | None` in
  render_labels signature and _validate_label_render_params to match
  render_shapes/render_points
- Update docstring to document that color-like values (named colors,
  hex strings, RGB(A) tuples) are accepted as literal colors
- Add tests for hex string and RGBA tuple color inputs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The palette/groups gating logic (set to None when col_for_color is
absent, warn when groups is provided without a column) was repeated
identically in _validate_label_render_params, _validate_points_render_params,
and _validate_shape_render_params. Extracted into a shared helper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change fill_alpha default from 0.4 to None so that _type_check_params
can extract the alpha from an RGBA color tuple, matching how points and
shapes already handle this.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the 3 ad-hoc tests (color_name, hex, rgba_tuple) with 4 tests
that mirror the existing points and shapes pattern: rgba_array, hex,
hex_with_alpha, and alpha_overwrites_opacity_from_color.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@timtreis timtreis merged commit 4fe68de into main Mar 11, 2026
4 checks passed
@timtreis timtreis deleted the feature/refactor_label_color_handling branch March 11, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants